package Arrays101.Day05;

public class Day05_4 {
    public static void main(String[] args) {
        int[] ints = sortArrayByParity(new int[]{3, 1, 2, 4});
        for (int i = 0; i < ints.length; i++) {

            System.out.println(ints[i]);
        }

    }

    /**
     * Sort Array By Parity
     *
     * Given an array nums of non-negative integers,
     * return an array consisting of all the even elements of nums, followed by all the odd elements of nums.
     * @param nums
     * @return
     */
    public static int[] sortArrayByParity(int[] nums) {
        int[] ints = new int[nums.length];
        int a=0;
        int b=nums.length-1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i]%2==0){
                ints[a]=nums[i];
                a++;
            }else {
                ints[b]=nums[i];
                b--;
            }
        }
        return ints;
    }
}
